﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static OMDRun.LogHelper;
using static System.Windows.Forms.LinkLabel;

namespace OMDRun
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            string [] lines= textBox1.Lines;
            MainExecute.Instance.DoActionLine(lines, "P_GetKanBanSublineDataByHour", (s) => {

                DelegateAction.DoInvoke(this, () => {
                    button1.Enabled = true;
                }); 
               
            });
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            button2.Enabled = false;
            string[] lines = textBox1.Lines;
            
                MainExecute.Instance.DoActionLine(lines, "P_GetKanBanSublineData", (s) => {

                    DelegateAction.DoInvoke(this, () => {
                        button2.Enabled = true;
                    });

                });
        }

        private void button4_Click(object sender, EventArgs e)
        {
            button4.Enabled = false;
            string[] lines = textBox1.Lines;
            
                MainExecute.Instance.DoActionLine(lines, "P_GetKanBanStationYield", (s) => {

                    DelegateAction.DoInvoke(this, () => {
                        button4.Enabled = true;
                    });

                });
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            btnAutoStop.Enabled = false;

            LogHelper.LogEventHandler+= LogHelper_LogEventHandler;
        }

        private void LogHelper_LogEventHandler(object sender, EventArgs e)
        {
            LogEntity logEntity = (LogEntity)sender;
            switch (logEntity.LogEnum)
            {
                case LogEnum.Info: { richTextBoxPanel1.LogMessage(logEntity.Message); break; }
                case LogEnum.Debug: { richTextBoxPanel1.LogWarning(logEntity.Message); break; }
                case LogEnum.Error: { richTextBoxPanel1.LogError(logEntity.Message); break; }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            button3.Enabled = false;
            string[] lines = textBox1.Lines;
            MainExecute.Instance.DoActionLine(lines, "P_GetKanBanLineData", (s) => {

                DelegateAction.DoInvoke(this, () => {
                    button3.Enabled = true;
                });

            });
          
        }

        private void button5_Click(object sender, EventArgs e)
        {
            button3.Enabled = false;
            string[] lines = textBox1.Lines;
            MainExecute.Instance.DoActionLine(lines, "P_GetKanBanSectionWipData", (s) => {

                DelegateAction.DoInvoke(this, () => {
                    button3.Enabled = true;
                });

            });
        }

        private void btnAutoRun_Click(object sender, EventArgs e)
        {
            btnAutoStart.Enabled = false;
            string[] lines = textBox2.Lines;
            MainExecute.Instance.AutoStart(lines);
            btnAutoStop.Enabled = true;
            textBox2.Enabled = false;
        }

        private void btnAutoStop_Click(object sender, EventArgs e)
        {
            MainExecute.Instance.AutoStop();
            btnAutoStart.Enabled=true;
            btnAutoStop.Enabled = false;
            textBox2.Enabled = true;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {

           
            Application.Exit();
        }

        private void btnStatict_Click(object sender, EventArgs e)
        {
            btnStatict.Enabled = false;
            string[] lines = textBox1.Lines;

            MainExecute.Instance.UpdateDBSTATISTICS(lines);
            btnStatict.Enabled = true;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            button6.Enabled = false;
            string[] lines = textBox1.Lines;
            MainExecute.Instance.DoActionLine(lines, "P_GetKanBanLineDataByHour", (s) => {

                DelegateAction.DoInvoke(this, () => {
                    button6.Enabled = true;
                });

            });
        }
    }
}
